package com.yukefms.jointpoint;

import com.yukefms.exceptions.D2PositionException;
import com.yukefms.jointpoint.interfaces.Position;

import java.io.Serializable;
import java.util.Objects;

/**
 * position for 2D
 */
public class D2Position implements Position, Serializable {

    protected double x ;
    protected double y ;

    public D2Position(double x, double y) {
        this.x = x;
        this.y = y;
    }

    @Override
    public double getX() {
        return x;
    }
    @Override
    public void setX(double x) {
        this.x = x;
    }
    @Override
    public double getY() {
        return y;
    }

    @Override
    public double getZ() {
        try {
            throw new D2PositionException("D2Position does not have Z perspective.");
        } catch (RuntimeException e) {
            e.printStackTrace();
        }
        return 0;
    }

    @Override
    public void setZ(double z) {
        try {
            throw new D2PositionException("D2Position does not have Z perspective.");
        } catch (RuntimeException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void setY(double y) {
        this.y = y;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (!(o instanceof Position)) {
            return false;
        }
        D2Position position = (D2Position) o;
        return Double.compare(position.x, x) == 0 &&
                Double.compare(position.y, y) == 0;
    }

    @Override
    public int hashCode() {
        return Objects.hash(x, y);
    }

    @Override
    public String toString() {
        return "Position{" +
                "x=" + x +
                ", y=" + y +
                '}';
    }
}
